﻿<UserControl x:Class="WhiteFlow.DevTrackingTool.UI.Views.ExpensesReportView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:wfBehaviors="clr-namespace:WhiteFlow.Wpf.Common.Behaviors;assembly=WhiteFlow.Wpf.Common"
             xmlns:wfCtlCommon="clr-namespace:WhiteFlow.Wpf.Controls.Common;assembly=WhiteFlow.Wpf.Controls"
             xmlns:wfCtlText="clr-namespace:WhiteFlow.Wpf.Controls.Text;assembly=WhiteFlow.Wpf.Controls"
             xmlns:behaviors="clr-namespace:WhiteFlow.DevTrackingTool.UI.Behaviors"
             xmlns:controls="clr-namespace:WhiteFlow.DevTrackingTool.UI.Controls"
             xmlns:converters="clr-namespace:WhiteFlow.DevTrackingTool.UI.Converters"
             mc:Ignorable="d"
             d:DesignHeight="359"
             d:DesignWidth="592">

    <UserControl.Resources>
        <converters:IsNullToBooleanConverter x:Key="IsNullToBooleanConverter" />
        <converters:ExpenseTypeConverter x:Key="ExpenseTypeConverter" />
    </UserControl.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <TextBlock Text="Expenses Report" 
                   Grid.Row="0"
                   Margin="20,0,0,0" 
                   FontSize="50" 
                   Foreground="{StaticResource ResourceKey=BlueFgBrush}" 
                   FontFamily="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Fonts/#BIRTH OF A HERO" />

        <Grid Grid.Row="1">
            <DockPanel LastChildFill="True">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="5" />
                        <RowDefinition Height="auto" MinHeight="120" MaxHeight="250" />
                    </Grid.RowDefinitions>

                    <DataGrid Name="ExpensesGrid"
                              ItemsSource="{Binding Path=OwnerWorksheetViewModel.SelectedTrackingDay.ExpenseReport.Expenses}" 
                              CanUserAddRows="False"
                              CanUserReorderColumns="False"
                              CanUserResizeRows="False"
                              CanUserSortColumns="False"
                              SelectedItem="{Binding Path=SelectedExpense, Mode=OneWayToSource}"
                              SelectedIndex="{Binding Path=SelectedExpenseIndex, Mode=OneWayToSource}"
                              SelectionUnit="FullRow"
                              AutoGenerateColumns="False"
                              Language="{Binding Path=OwnerWorksheetViewModel.Worksheet.WorksheetSettings.Currency, Mode=OneWay, ConverterCulture='en-US'}"
                              behaviors:DataGridBehavior.EditOnKeyDown="True">

                        <DataGrid.Columns>
                            <DataGridTemplateColumn Header="Expense Type" Width="auto" MinWidth="55">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border BorderThickness="1" BorderBrush="Transparent">
                                            <TextBlock Text="{Binding Path=ExpenseType, Converter={StaticResource ResourceKey=ExpenseTypeConverter}}" />
                                        </Border>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                                <DataGridTemplateColumn.CellEditingTemplate>
                                    <DataTemplate>
                                        <ComboBox Text="{Binding Path=ExpenseType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource ResourceKey=ExpenseTypeConverter}}"
                                                  Style="{StaticResource ResourceKey=WhiteBgComboBoxType}">
                                            <ComboBoxItem Content="" />
                                            <ComboBoxItem Content="Fuel" />
                                            <ComboBoxItem Content="Highway Tickets" />
                                            <ComboBoxItem Content="Meal" />
                                            <ComboBoxItem Content="Accomodation" />
                                        </ComboBox>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellEditingTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTemplateColumn Header="Description" Width="*">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border BorderThickness="1" BorderBrush="Transparent">
                                            <TextBlock Text="{Binding Path=Description}" />
                                        </Border>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                                <DataGridTemplateColumn.CellEditingTemplate>
                                    <DataTemplate>
                                        <wfCtlText:AutoCompleteTextBox SelectedItem="{Binding Path=Description, Mode=TwoWay}" AutoCompletionSource="{Binding Path=DataContext.OwnerWorksheetViewModel.Worksheet.AllExpensesDescriptions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" AllowSelectionNotInList="False" DefaultValueSelectionMode="Null" PopupMaxHeight="150" BorderBrush="Transparent" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellEditingTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTextColumn Header="Kilometers" Binding="{Binding Path=Kilometers}" Width="auto" />
                            <DataGridTextColumn Header="Amount" Binding="{Binding Path=Amount, StringFormat='{}{0:c}'}" Width="auto" />
                            <DataGridTextColumn Header="Attachments #" Binding="{Binding Path=Attachments}" Width="auto" />
                        </DataGrid.Columns>
                    </DataGrid>

                    <GridSplitter Grid.Row="1"
                                  Background="Transparent"
                                  Height="5"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch"
                                  ResizeBehavior="PreviousAndNext"
                                  ResizeDirection="Rows" />

                    <Border Grid.Row="2"
                            Padding="5"
                            TextElement.Foreground="{StaticResource ResourceKey=ContentsBgBrush}" 
                            TextElement.FontSize="14"
                            BorderThickness="1"
                            BorderBrush="{StaticResource ResourceKey=DataGridLinesColor}">
                        <DockPanel LastChildFill="True">
                            <TextBlock Text="Summary"
                                       DockPanel.Dock="Top"
                                       FontSize="30"
                                       FontFamily="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Fonts/#BIRTH OF A HERO" />

                            <Grid Margin="5,10,5,5">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto" />
                                    <ColumnDefinition Width="auto" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto" />
                                    <RowDefinition Height="auto" />
                                </Grid.RowDefinitions>

                                <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0">
                                    <Border VerticalAlignment="Center">
                                        <wfCtlCommon:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Icons/Application/16x16/money_dollar.png" />
                                    </Border>
                                    <Border VerticalAlignment="Center" Margin="2,0,0,0">
                                        <TextBlock Text="Total expenses: " VerticalAlignment="Center" />
                                    </Border>
                                </StackPanel>

                                <TextBlock Grid.Row="0"
                                           Grid.Column="1"
                                           Language="{Binding Path=OwnerWorksheetViewModel.Worksheet.WorksheetSettings.Currency, Mode=OneWay, ConverterCulture='en-US'}"
                                           Text="{Binding Path=OwnerWorksheetViewModel.SelectedTrackingDay.ExpenseReport.TotalExpense, StringFormat='{}{0:c}'}" />
                            </Grid>
                        </DockPanel>
                    </Border>
                </Grid>

                <DockPanel.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=OwnerWorksheetViewModel.SelectedTrackingDay.ExpenseReport, Mode=OneWay, Converter={StaticResource ResourceKey=IsNullToBooleanConverter}}" Value="True">
                                <Setter Property="Control.Visibility" Value="Collapsed" />
                                <Setter Property="Control.Opacity" Value="0" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=OwnerWorksheetViewModel.SelectedTrackingDay.ExpenseReport, Mode=OneWay, Converter={StaticResource ResourceKey=IsNullToBooleanConverter}}" Value="False">
                                <Setter Property="Control.Visibility" Value="Visible" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </DockPanel.Style>
            </DockPanel>
        </Grid>
    </Grid>
</UserControl>